<?php

/*
 * This file is part of the php-phantomjs.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace lemon\phantomjs\Tests\Unit\Procedure;

use Twig_Environment;
use Twig_Loader_String;
use lemon\phantomjs\Engine;
use lemon\phantomjs\Cache\FileCache;
use lemon\phantomjs\Cache\CacheInterface;
use lemon\phantomjs\Parser\JsonParser;
use lemon\phantomjs\Parser\ParserInterface;
use lemon\phantomjs\Template\TemplateRenderer;
use lemon\phantomjs\Template\TemplateRendererInterface;
use lemon\phantomjs\Procedure\ProcedureFactory;

/**
 * PHP PhantomJs
 *
 * @author Jon Wenmoth <contact@jonnyw.me>
 */
class ProcedureFactoryTest extends \PHPUnit_Framework_TestCase
{

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++++++ TESTS ++++++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/

	/**
	 * Test factory can create instance of
	 * procedure.
	 *
	 * @access public
	 * @return void
	 */
	public function testFactoryCanCreateInstanceOfProcedure(){
		$engine	= $this->getEngine();
		$parser	= $this->getParser();
		$cache	 = $this->getCache();
		$renderer  = $this->getRenderer();

		$procedureFactory = $this->getProcedureFactory($engine, $parser, $cache, $renderer);

		$this->assertInstanceOf('\lemon\phantomjs\Procedure\Procedure', $procedureFactory->createProcedure());
	}

/** +++++++++++++++++++++++++++++++++++ **/
/** ++++++++++ TEST ENTITIES ++++++++++ **/
/** +++++++++++++++++++++++++++++++++++ **/

	/**
	 * Get procedure factory instance.
	 *
	 * @access protected
	 * @param  \lemon\phantomjs\Engine							 $engine
	 * @param  \lemon\phantomjs\Parser\ParserInterface			 $parser
	 * @param  \lemon\phantomjs\Cache\CacheInterface			   $cacheHandler
	 * @param  \lemon\phantomjs\Template\TemplateRendererInterface $renderer
	 * @return \lemon\phantomjs\Procedure\ProcedureFactory
	 */
	protected function getProcedureFactory(Engine $engine, ParserInterface $parser, CacheInterface $cacheHandler, TemplateRendererInterface $renderer){
		$procedureFactory = new ProcedureFactory($engine, $parser, $cacheHandler, $renderer);

		return $procedureFactory;
	}

	/**
	 * Get engine.
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Engine
	 */
	protected function getEngine(){
		$engine = new Engine();

		return $engine;
	}

	/**
	 * Get parser.
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Parser\JsonParser
	 */
	protected function getParser(){
		$parser = new JsonParser();

		return $parser;
	}

	/**
	 * Get cache.
	 *
	 * @access protected
	 * @param  string							$cacheDir  (default: '')
	 * @param  string							$extension (default: 'proc')
	 * @return \lemon\phantomjs\Cache\FileCache
	 */
	protected function getCache($cacheDir = '', $extension = 'proc'){
		$cache = new FileCache(($cacheDir ? $cacheDir : sys_get_temp_dir()), 'proc');

		return $cache;
	}

	/**
	 * Get template renderer.
	 *
	 * @access protected
	 * @return \lemon\phantomjs\Template\TemplateRenderer
	 */
	protected function getRenderer(){
		$twig = new Twig_Environment(
			new Twig_Loader_String()
		);

		$renderer = new TemplateRenderer($twig);

		return $renderer;
	}
}
